import numpy as np
import struct


def validate(valid_file: str, source_file: str, result_file: str):
    with open(valid_file, 'wb') as fileSave:
        with open(source_file, 'rb') as fileReader1:
            with open(result_file, 'rb') as fileReader2:
                for i in range(135 * 240 * 3):
                    a = fileReader1.read(1)
                    b = fileReader2.read(1)
                    if a and b:
                        a = struct.unpack('B', a)
                        b = struct.unpack('B', b)
                        fileSave.write(np.uint8(a[0] ^ b[0]))  # 异或运算


if __name__ == '__main__':
    bin_file = input('请输入原二进制文件名:')  # source.bin
    decode_bin_file = input('请输入解码后的二进制文件名:')  # result.bin
    valid_bin_file = input('请输入二进制验证文件名:')  # valid.bin

    # 验证二进制文件
    validate(valid_bin_file, bin_file, decode_bin_file)
